const express = require('express');
const login = express.Router();
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const secret = 'userToken';
const { Account } = require('../mongoose/Schema');
login.post('/login', async (req, res) => {
    const query = req.body;
    // const result = await Account.findOne({username:"12213"});
    // console.log('登录账户信息', result);
    const data = await Account.create({
        username:"",
        password:"123456"
    })
    if(result){
        let bool = await bcrypt.compare("123456", result.password);
        if(bool === true){
            console.log(result._id);
            const token = jwt.sign({name:result._id.toString()}, secret, { expiresIn: '1h' });
            console.log('得到token', token);
            const decoded = jwt.verify(token, secret);
            console.log('Decoded Payload:', decoded);
        }
    }
   
    res.send('login');
});

module.exports = login;